/* Global styles and responsive design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    overflow: auto;
}

/* Container adapts to iframe or full screen */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
}

/* Full screen mode detection */
@media (min-height: 500px) {
    .container {
        height: calc(100vh - 56px);
    }
}

/* Control panel styling with cognitive load principles */
.control-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-around;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 120px;
}

.control-group label {
    font-weight: 600;
    font-size: 12px;
    color: #333;
    text-align: center;
    /* Added margin to prevent text overlap */
    margin-bottom: 4px;
}

/* Button group styling for clear visual hierarchy */
.button-group {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    /* Added margin to prevent overlap */
    margin: 2px 0;
}

.control-btn {
    padding: 8px 12px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.3s ease;
    min-height: 36px; /* Touch-friendly target size */
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Added line-height for better text positioning */
    line-height: 1.2;
    /* Prevent text wrapping */
    white-space: nowrap;
}

.control-btn:hover {
    background: #f0f8ff;
    border-color: #4CAF50;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.control-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
    box-shadow: 0 3px 10px rgba(76, 175, 80, 0.3);
}

/* Resistor controls with clear visual feedback */
.resistor-controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    /* Added margin to prevent overlap */
    margin-top: 4px;
}

.resistor-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px; /* Increased gap to prevent text overlap */
}

.resistor-input label {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    /* Added margin for better spacing */
    margin-bottom: 2px;
}

.resistor-input input[type="range"] {
    width: 80px;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    cursor: pointer;
    /* Added margin for better spacing */
    margin: 4px 0;
}

.resistor-input input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.resistor-input span {
    font-size: 11px;
    font-weight: 600;
    color: #333;
    background: #f0f0f0;
    padding: 3px 8px; /* Increased padding for better readability */
    border-radius: 4px;
    /* Added margin for better spacing */
    margin-top: 2px;
    /* Prevent text wrapping */
    white-space: nowrap;
}

/* NEW: Component description panel styling */
.component-description {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 12px 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #4CAF50;
    margin: 5px 0;
}

.component-text {
    font-size: 13px;
    line-height: 1.4;
    color: #333;
    font-weight: 500;
    text-align: left;
    /* Smooth transition for text changes */
    transition: opacity 0.3s ease-in-out;
}

.component-text.fade-out {
    opacity: 0;
}

.component-text.fade-in {
    opacity: 1;
}

/* Circuit visualization area */
.circuit-area {
    flex: 1;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px; /* Increased gap to prevent overlap */
    position: relative;
}

#circuit-svg {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: #fafafa;
    /* Added minimum height to prevent text compression */
    min-height: 200px;
}

/* Results panel with clear information hierarchy */
.results-panel {
    display: flex;
    justify-content: space-around;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 12px; /* Increased padding to prevent text overlap */
    border: 1px solid #e0e0e0;
    /* Added margin for better spacing */
    margin-top: 8px;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px; /* Increased gap to prevent text overlap */
    font-size: 12px;
    /* Added minimum width to prevent crowding */
    min-width: 80px;
}

.result-item span:first-child {
    color: #666;
    font-weight: 500;
    /* Added line-height for better text positioning */
    line-height: 1.3;
    /* Prevent text wrapping */
    white-space: nowrap;
}

.result-item span:last-child {
    color: #333;
    font-weight: 700;
    font-size: 14px;
    background: white;
    padding: 6px 10px; /* Increased padding for better readability */
    border-radius: 4px;
    border: 1px solid #ddd;
    /* Added line-height for better text positioning */
    line-height: 1.2;
    /* Prevent text wrapping */
    white-space: nowrap;
}

/* SVG element styling for clear visual representation */
/* MODIFIED: Enhanced SVG text styling to prevent wire overlap */
#circuit-svg text {
    font-family: 'Segoe UI', sans-serif;
    user-select: none;
    /* Added better text positioning */
    dominant-baseline: central;
    /* Prevent text overlap with improved spacing */
    letter-spacing: 0.5px;
    /* Added text shadow for better visibility over wires */
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
    /* Ensure text appears above wires */
    z-index: 10;
}

/* MODIFIED: Special styling for component labels to ensure visibility */
#circuit-svg .component-label {
    fill: #333;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 4px;
    border-radius: 3px;
}

/* MODIFIED: Junction labels styling for parallel circuit */
#junction1-label, #junction2-label {
    fill: #666;
    font-size: 9px;
    font-weight: 500;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9);
}

#circuit-svg .wire {
    stroke: #333;
    stroke-width: 3;
    fill: none;
}

/* Current flow animation */
.current-dot {
    fill: #FF4444;
    animation: flow 2s linear infinite;
}

@keyframes flow {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* Bulb brightness animation */
.bulb-bright {
    animation: glow 0.5s ease-in-out;
}

@keyframes glow {
    0% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Mobile-first responsive design with improved text spacing */
@media (max-width: 768px) {
    .control-panel {
        padding: 12px; /* Increased padding for mobile */
        gap: 12px; /* Increased gap to prevent overlap */
    }
    
    .control-group {
        min-width: 110px; /* Increased minimum width */
    }
    
    .control-group label {
        font-size: 11px; /* Slightly smaller font for mobile */
        margin-bottom: 6px; /* Increased margin */
    }
    
    .control-btn {
        padding: 8px 10px; /* Adjusted padding */
        font-size: 10px;
        min-width: 55px; /* Increased minimum width */
        min-height: 38px; /* Increased height for better touch targets */
    }
    
    .resistor-controls {
        gap: 12px; /* Increased gap for mobile */
    }
    
    .resistor-input {
        gap: 8px; /* Increased gap for mobile */
    }
    
    .resistor-input input[type="range"] {
        width: 70px; /* Adjusted width for mobile */
        margin: 6px 0; /* Increased margin */
    }
    
    /* Component description adjustments for mobile */
    .component-description {
        padding: 10px 12px;
        margin: 3px 0;
    }
    
    .component-text {
        font-size: 12px;
        line-height: 1.3;
    }
    
    .results-panel {
        padding: 10px; /* Increased padding for mobile */
        gap: 8px; /* Added gap between items */
    }
    
    .result-item {
        font-size: 11px;
        min-width: 70px; /* Adjusted minimum width for mobile */
        gap: 8px; /* Increased gap for mobile */
    }
    
    .result-item span:last-child {
        font-size: 13px; /* Slightly smaller for mobile */
        padding: 4px 8px; /* Adjusted padding */
    }
    
    /* SVG text adjustments for mobile */
    #circuit-svg text {
        font-size: 10px; /* Smaller font size for mobile */
        /* MODIFIED: Enhanced text shadow for mobile visibility */
        text-shadow: 1px 1px 3px rgba(255, 255, 255, 0.9);
    }
}

/* Tooltip styling for additional information */
[title] {
    cursor: help;
}

/* Enhanced visual feedback for interactive elements */
.control-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.2);
}

/* Accessibility improvements */
.control-btn:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

input[type="range"]:focus {
    outline: 2px solid #4CAF50;
    outline-offset: 2px;
}

/* Additional improvements to prevent text overlap */
.control-panel > * {
    flex-shrink: 0; /* Prevent shrinking that causes overlap */
}

.button-group > * {
    flex-shrink: 0; /* Prevent button shrinking */
}

/* Ensure proper text rendering */
* {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Compact layout for shorter viewports to fit within screen space */
@media (max-height: 700px) {
    .control-panel { padding: 10px; gap: 10px; }
    .component-description { padding: 10px 12px; margin: 4px 0; }
    .circuit-area { padding: 10px; gap: 8px; }
    #circuit-svg { min-height: 160px; }
    .results-panel { padding: 8px; }
}

/* Ultra-compact adjustments for very small heights */
@media (max-height: 600px) {
    .control-btn { min-height: 32px; padding: 6px 8px; font-size: 10px; }
    .component-text { font-size: 12px; }
    .result-item { font-size: 11px; }
    .result-item span:last-child { font-size: 13px; padding: 4px 6px; }
}
